<?php
	/**
	 * 二维码分享
	 */
    class ShareByQrcode extends APIBase {
		
		public $tag = "ShareByQrcode";
    	public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}
		public function logic() {
			$uid = $this->uid;
			$path = "QRimage";
			$url = Config::$qrcode_url;
            if (!is_dir($path)){
				mkdir($path,0777,true);//没有文件夹则创建
				$fp = @fopen($path, 'wb');//获取文件夹是否有读写权限
			    if($fp==false) chmod($path, 0777);//把文件夹权限改成最大
				@fclose($fp);
				QRcode::png($url,$path.'/qrcode.png','L',6,2);
			    $this->returnData(array('url'=>"http://".$_SERVER['HTTP_HOST']."/majapi/QRimage/qrcode.png")); 
				
			}else{
				if(!file_exists($path.'/qrcode.png')){
					QRcode::png($url,$path.'/qrcode.png','L',6,2);
			        $this->returnData(array('url'=>"http://".$_SERVER['HTTP_HOST']."/majapi/QRimage/qrcode.png")); 
				}else{
				$this->returnData(array('url'=>"http://".$_SERVER['HTTP_HOST']."/majapi/QRimage/qrcode.png"));
				}				
			}

		}
		
        public function after() {
			$this->deinitMysql();
		}
    }
?>
